package sqlAndIo.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Date;

import sqlAndIo.pojo.Book;


public class IOBook {

	    private String fileName;  
	      
	    public IOBook(){  
	          
	    }  
	      
	    public IOBook(String fileName){  
	        this.fileName=fileName;  
	    }  
	      
	    public void saveToFile(){  
	        try {  
	            //写对象流的对象  
	            ObjectOutputStream o=new ObjectOutputStream(new FileOutputStream(fileName));  
	            for(int i=1;i<10001;i++)
	            {
	            	Book book=new Book(null,"java"+i,new Date(),"bruce",50,true,true);
	            	o.writeObject(book);
	            }
	            o.writeObject(null);
	            o.flush();
	            o.close();                        //关闭文件流  
	        } catch (FileNotFoundException e) {  
	            e.printStackTrace();  
	        } catch (IOException e) {  
	            e.printStackTrace();  
	        }   
	    } 
	   
	}  
